package com.sykj.bsc.zjj.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sykj.bsc.zjj.bean.Bis_custom_user;
import com.sykj.bsc.zjj.service.Bis_custom_userService1;

/**
 * 前台
 * 顾客管理
 * @author Lenovo G50-80
 *
 */
@Controller
@RequestMapping("proltal/zjj1")
public class Bis_custom_userController1 {
	@Autowired
	private Bis_custom_userService1 bcus1;
	
	/**
	 * 查询所有
	 * @param map
	 * @param bis_custom_user
	 * @return
	 */
	@RequestMapping("selectBis_custom_user1")
	public String selectBis_custom_user1(Map<String, Object> map,Model model,Bis_custom_user bis_custom_user,@RequestParam(value = "page", defaultValue = "1") Integer page,HttpSession session) {
		PageHelper.startPage(page,2);
		//session
		String shop_id=(String)session.getAttribute("shop_id");
		bis_custom_user.setShop_id(shop_id);
		//bis_custom_user.setShop_id("10000001");
		
		//定值
		if(bis_custom_user!=null) getbis_custom_user(model, bis_custom_user);
		
		List<Map> list = this.bcus1.selectBis_custom_user1(bis_custom_user);
		PageInfo<Map> info = new PageInfo<>(list);
		map.put("info", info);
		return "foreground/zjj/Customermanagement";		
	}
	
	/**
	 * 条件查询定值方法
	 * @param model
	 * @param bcu
	 */
	private void  getbis_custom_user(Model model,Bis_custom_user bcu) {
		if (bcu.getMobile()!=null && !bcu.getMobile().equals("")) {
			model.addAttribute("mobile", bcu.getMobile());
		}
		if (bcu.getUsername()!=null && !bcu.getUsername().equals("")) {
			model.addAttribute("username", bcu.getUsername());
		}
		if (bcu.getBorn_date()!=null && !bcu.getBorn_date().equals("")) {
			model.addAttribute("born_date", bcu.getBorn_date());
		}
		if (bcu.getBeauty_num()!=null && !bcu.getBeauty_num().equals("")) {
			model.addAttribute("beauty_num", bcu.getBeauty_num());
		}
		if (bcu.getBuy_num()!=null && !bcu.getBuy_num().equals("")) {
			model.addAttribute("buy_num", bcu.getBuy_num());
		}
	}
	
	
	/**
	 * 查看资料
	 * 根据ID查询
	 * @param custom_user_id
	 * @param map
	 * @return
	 */
	@RequestMapping("findByIdBis_custom_user1/{custom_user_id}")
	public String findByIdBis_custom_user1(@PathVariable("custom_user_id") String custom_user_id,Bis_custom_user bcu1,Map<String, Object> map,HttpSession session){
		bcu1.setCustom_user_id(custom_user_id);
		
		//session
		String shop_id = (String) session.getAttribute("shop_id");
		bcu1.setShop_id(shop_id);
		//bcu1.setShop_id("10000001");
		
		Bis_custom_user bcu = this.bcus1.findByIdBis_custom_user1(bcu1);
		map.put("bcu", bcu);
		return "foreground/zjj/Customermanagement1";
	}
	
	/**
	 * 消费情况
	 * 根据ID查询
	 * @param custom_user_id
	 * @param map
	 * @return
	 */
	@RequestMapping("findByIdBis_custom_user2")
	public String findByIdBis_custom_user2(String custom_user_id,Bis_custom_user bcu,Model model,Map<String, Object> map,@RequestParam(value = "page", defaultValue = "1") Integer page,HttpSession session){		
		PageHelper.startPage(page,5);
		bcu.setCustom_user_id(custom_user_id);
		
		//session
		String shop_id = (String) session.getAttribute("shop_id");
		bcu.setShop_id(shop_id);
		//bcu.setShop_id("10000001");
		
		//定值
		if(bcu!=null) getBis_custom_user1(model, bcu);
		
		List<Map> list = this.bcus1.findByIdBis_custom_user2(bcu);
		map.put("custom_user_id", custom_user_id);
		PageInfo<Map> info = new PageInfo<>(list);
		map.put("info", info);
		return "foreground/zjj/Customermanagement2";
	}
	
	/**
	 * 条件查询定值方法
	 * @param model
	 * @param bcu
	 */
	private void  getBis_custom_user1(Model model,Bis_custom_user bcu) {
		if (bcu.getOrder_id()!=null && !bcu.getOrder_id().equals("")) {
			model.addAttribute("order_id", bcu.getOrder_id());
		}
		if (bcu.getOrder_content()!=null && !bcu.getOrder_content().equals("")) {
			model.addAttribute("order_content", bcu.getOrder_content());
		}
		if (bcu.getPay_way()!=null && !bcu.getPay_way().equals("")) {
			model.addAttribute("pay_way", bcu.getPay_way());
		}
	}
	
}
